home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2109 / 2109.xpi / chrome / febe.jar / content / febeVerifyext.js < prev    next >
Text File  |  2009-10-13  |  8KB  |  223 lines

  1. // author: Chuck Baker
  2. // contact: febe@customsoftwareconsult.com
  3. // Version 6.3
  4.  
  5. febeSetMsgs();
  6.  
  7. function febeVerifyExtension(){
  8.     // Verify all entries in the profile/extensions directory. 
  9.     //   To pass validation, an entry must:
  10.     //     (1)  Be a non-empty directory that is named with a proper GUID - either  {xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx}, or a pseudo-email: xxx@something.tld
  11.     //     (2)  Contain a parsable 'install.rdf' file that identifies the add-on as either an extension (type 2) or theme (type 4)
  12.     //  A 'staged-xpis' directory indicates there are add-ons pending install.
  13.     
  14.     Application.storage.set("fixverifyerrors", false);    // Fix verify errors?
  15.     febeVerifyExtensions();
  16.     if(Application.storage.get("fixverifyerrors", false)){febeVerifyExtensions();}    // Run again to fix
  17.     return true;
  18. }//function febeVerifyExtension(){
  19.  
  20. function febeVerifyExtensions(){
  21.     window.document.title = febeMsg[237];
  22.     Application.storage.set("runningVerifyExtRoutine", true);
  23.     var fixIt = Application.storage.get("fixverifyerrors", false);
  24.     // Create pointer to profile directory
  25.     febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
  26.     var extDir = febeProfDir.clone();
  27.     extDir.append("extensions");
  28.     var errCnt = 0;
  29.     var extCnt = 0;
  30.     var mode = febePrefs.getCharPref("extensions.febe.verifyMode");    // 'strict' or 'lenient'
  31.     var entries = extDir.directoryEntries;
  32.     while(entries.hasMoreElements()){
  33.         var entry = entries.getNext();   
  34.         entry.QueryInterface(Ci.nsILocalFile);
  35.         if(!entry.isDirectory()){
  36.             if(fixIt){
  37.                 if(febeDeleteInvalidExt(entry.path)){
  38.                     var tmp = "<p><b>"+febeMsg[226]+"</b> "+febeMsg[220].replace("%PATH%",entry.path)+"  <b>"+febeMsg[227]+"</b><br></p>";
  39.                     febeprt(tmp);
  40.                     continue;
  41.                 }//if
  42.             }//if
  43.             var tmp = "<p>***";
  44.             tmp += "<b>"+febeMsg[226]+"</b><br>";
  45.             tmp += "<b>"+febeMsg[220].replace("%PATH%",entry.path)+"</b><br>";
  46.             tmp += "***</p>";
  47.             febeprt(tmp,"red",15);    // Not a directory
  48.             errCnt++;
  49.             continue;
  50.         }else{
  51.             if(entry.leafName == "staged-xpis") {    // Pending extension installs
  52.                 if(fixIt){
  53.                     if(febeDeleteInvalidExt(entry.path)){
  54.                         var tmp = "<p><b>"+febeMsg[203]+"  "+febeMsg[227]+"</b><br></p>";
  55.                         febeprt(tmp);
  56.                         continue;
  57.                     }//if
  58.                 }//if
  59.                 var tmp = "<p>***";
  60.                 tmp += "<b>"+febeMsg[203]+"***</p></b><br>";
  61.                 febeprt(tmp,"red",15);    // Not a directory
  62.                 errCnt++;
  63.                 continue;
  64.             }//if
  65.             if(!febeIsValidGUID(entry.leafName,mode)){
  66.                 if(fixIt){
  67.                     if(febeDeleteInvalidExt(entry.path)){
  68.                         var tmp = "<p><b>"+febeMsg[239].replace("%GUID%",entry.leafName)+"  "+febeMsg[227]+"</b><br></p>";
  69.                         febeprt(tmp);
  70.                         continue;
  71.                     }//if
  72.                 }//if
  73.                 var tmp = "<p>***";
  74.                 tmp += "<b>"+febeMsg[239].replace("%GUID%",entry.leafName)+"***</p></b><br>";
  75.                 febeprt(tmp,"red",15);    // Not a valid GUID
  76.                 errCnt++;
  77.                 continue;
  78.             }//if
  79.         }//if
  80.         var GUID = extDir.clone();
  81.         GUID.append(entry.leafName);
  82.         var entries2 = GUID.directoryEntries;
  83.         if(!entries2.hasMoreElements()){
  84.             if(!entry.isDirectory()){
  85.                 if(fixIt){
  86.                     if(febeDeleteInvalidExt(entry.path)){
  87.                         var tmp = "<p><b>"+febeMsg[226]+"</b> "+febeMsg[221].replace("%GUID%",GUID.path)+"  <b>"+febeMsg[227]+"</b><br></p>";
  88.                         febeprt(tmp);
  89.                         continue;
  90.                     }//if
  91.                 }//if
  92.                 var tmp = "<p>***";
  93.                 tmp += "<b>"+febeMsg[226]+"</b><br>";
  94.                 tmp += "<b>"+febeMsg[221].replace("%GUID%",GUID.path)+"</b><br>";
  95.                 tmp += "***</p>";
  96.                 febeprt(tmp,"red",15);    // Directory is empty
  97.                 errCnt++;
  98.                 continue;
  99.             }//if
  100.         }//if
  101.         GUID.append("install.rdf");
  102.         if(!GUID.exists()){
  103.             if(fixIt){
  104.                 if(febeDeleteInvalidExt(entry.path)){
  105.                     var tmp = "<p><b>"+febeMsg[226]+"</b> "+febeMsg[222].replace("%ITEM%",GUID.path)+"  <b>"+febeMsg[227]+"</b><br></p>";
  106.                     febeprt(tmp);
  107.                     continue;
  108.                 }//if
  109.             }//if
  110.             var tmp = "<p>***";
  111.             tmp += "<b>"+febeMsg[226]+"</b><br>";
  112.             tmp += febeMsg[222].replace("%ITEM%",GUID.path)+"<br>";
  113.             tmp += "***</p>";
  114.             febeprt(tmp,"red",15);    // No install.rdf
  115.             errCnt++;
  116.             continue;
  117.         }//if
  118.         
  119.         var thisExt = new febeExtInfo(GUID.parent.leafName);
  120.         if(thisExt.isInvalid){
  121.             if(fixIt){
  122.                 if(febeDeleteInvalidExt(entry.path)){
  123.                     var tmp = "<p><b>"+febeMsg[226]+"</b> "+febeMsg[222].replace("%ITEM%",GUID.path)+"  <b>"+febeMsg[227]+"</b><br></p>";
  124.                     febeprt(tmp);
  125.                     continue;
  126.                 }//if
  127.             }//if
  128.             var tmp = "<p>***";
  129.             tmp += "<b>"+febeMsg[226]+"</b><br>";
  130.             tmp += febeMsg[305].replace("%GUID%",GUID.parent.leafName)+"<br>";
  131.             tmp += "***</p>";
  132.             febeprt(tmp,"red",15);    // Not in extension manager
  133.             errCnt++;
  134.             continue;
  135.         }//if
  136.         var extName = thisExt.name;
  137.         var extVer = febeStripSpaces(thisExt.version);
  138.         var extIsDisabled = thisExt.isDisabled;
  139.         var extIcon = thisExt.iconURL;
  140.         if(extIsDisabled){extIcon = "chrome://febe/skin/disabled.png";}
  141.         var extHome = thisExt.homepageURL;
  142.  
  143.         var eType = thisExt.type;                            // 2=Extension, 4=Theme
  144.         if(eType != 2 && eType != 4){continue;}            // Not an extension or theme ... what is it?
  145.         var tmp = "<img src='"+extIcon+"' ";
  146.         tmp += "style='border: 0px solid ; width: 16px; height: 16px;'/> ";
  147.         tmp += thisExt.guid+" <b>"+extName+"</b>";
  148.         if(extIsDisabled) tmp += " <i>(disabled)</i>";
  149.         tmp += " - OK";
  150.         if(eType == 2){
  151.             febeprt(tmp,"blue");    // Extension
  152.         }//if
  153.         if(eType == 4){
  154.             febeprt(tmp,"green");    // Theme    
  155.         }//if
  156.         extCnt++;
  157.     }//while
  158.     if(errCnt == 0){
  159.         var tmp = febeMsg[223].replace("%CNT%",extCnt);  // All OK
  160.         febeprt(tmp,"purple");
  161.         febeAlert(tmp);
  162.     }else{
  163.         var tmp = "<style>color: red; font-size: 15px;</style>";
  164.         tmp += febeMsg[224] + "\n";
  165.         tmp += "<style>color: purple; font-size: 15px;</style>"+febeMsg[225];
  166.         Application.storage.set("alertsound", "failure");
  167.         fixIt = febeConfirm(tmp);
  168.         Application.storage.set("fixverifyerrors", fixIt);
  169.     }//if
  170.     var box = document.getElementById("messages");
  171.     box.contentDocument.close();
  172.     Application.storage.set("runningVerifyExtRoutine", false);
  173.     return true;
  174. }//febeVerifyExtensions()
  175.  
  176. function febeDeleteInvalidExt(path){
  177.     var aFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  178.     if (!aFile) return false;
  179.     aFile.initWithPath(path);
  180.     try{
  181.         aFile.remove(true);
  182.     }catch(e){
  183.         Application.storage.set("alertsound", "failure");
  184.         febeFatal(e,febeMsg[306]+"\n"+path);
  185.         return false;
  186.     }//try/catch
  187.     return true;    
  188. }//febeDeleteInvalidExt()
  189.  
  190. function febeprt(txt,color,size){
  191.     // Display content in log window
  192.     if(!color) color="black";
  193.     if(!size) size = 12;
  194.     var box = document.getElementById("messages");
  195.     txt = "<span style='font-family: Courier New,Courier,monospace; font-size: "+size+"px; color: "+color+";'>"+txt+"<br></span>"
  196.     box.contentDocument.write(txt);
  197.     var scrollBox = box.contentWindow.document.body;
  198.     scrollBox.scrollTop = scrollBox.scrollHeight - scrollBox.clientHeight
  199.     return true;
  200. }//febeprt()
  201.  
  202. function febeIsValidGUID(guid, mode){
  203.   // Validate GUID
  204.     var mask = " `!$%^&*()+=?,'\"";    // Invalid characters
  205.     for (var i = 0; i < guid.length; i++){
  206.         var c = guid.charAt(i);
  207.         if(mask.indexOf(c) != -1 ){return false;};
  208.     }//for
  209.     
  210.     // GUID format: {xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx}
  211.     var re = /^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/
  212.     var guidOK = Boolean(guid.match(re));
  213.  
  214.     // Email format (valid)  i.e., "something@domain.tld"
  215.     var re = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/
  216.     var emailOK = Boolean(guid.match(re));
  217.     
  218.     // Email format (malformed) - No TLD
  219.     var re = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)$/    
  220.     var malformedemailOK = Boolean(!guid.match(re));
  221.     if(mode == "lenient"){malformedemailOK = true;}
  222.     return Boolean(guidOK || emailOK || malformedemailOK);
  223. }//febeIsValidGUID()